<template>
    <div class="">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="600px"
                :close-on-click-modal="false"
                @close="close"
        >
            <el-form ref="form" :model="form" label-width="120px">
                <el-form-item label="排序" prop="sort">
                    <el-input v-model.trim="form.sort" autocomplete="off" placeholder="请输入排序" ></el-input>
                </el-form-item>
                <el-form-item label="标签名称" prop="name" :required="true">
                    <el-input v-model.trim="form.name" autocomplete="off" placeholder="请输入标签名称"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button size="medium" @click="close">取 消</el-button>
                <el-button size="medium" type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import { saveLabel } from "@/api/good";
    export default {
        name: "goodlistedit",
        created() {
        },
        data() {
            return {
                form: {
                    id:'',
                    sort: "1",
                    name: "",
                    storeId:'',
                },
                title: "",
                dialogFormVisible: false,
            }
        },
        components: {
        },
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "添加";
                } else {
                    this.title = "编辑";
                    this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            close() {
                this.$refs["form"].resetFields();
                this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            setStoreId(storeId){
              this.form.storeId = storeId
            },
            save() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        const { msg } = await saveLabel(this.form);
                        this.$baseMessage(msg, "success");
                        this.$emit("fetchData");
                        this.close();
                    } else {
                        return false;
                    }
                });
            },
        }
    };
</script>
